package com.github.szhittech.bean;


import java.util.Collections;
import java.util.List;

public class LibraryBean implements Comparable<LibraryBean> {
    private String name;
    private String group;
    private String detail;
    private String docLink;
    private List<VersionBean> versions;

    public String getDocLink() {
        return docLink;
    }

    public VersionBean getLastVersion() {
        VersionBean version = Collections.max(versions);
        return version;
    }


    public String toDescribetion() {
        VersionBean ver = getLastVersion();
        String msg = ver.getDescription();
        return msg;
    }

    public void setDocLink(String docLink) {
        this.docLink = docLink;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public List<VersionBean> getVersions() {
        return versions;
    }

    public void setVersions(List<VersionBean> versions) {
        this.versions = versions;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getGroupName() {
        return String.format("%s:%s", group, name);
    }

    public String getFullyQualifiedName(int index) {
        VersionBean version = versions.get(index);
        return String.format("%s:%s:%s", group, name, version.getVersionName());
    }

    public String getFullyQualifiedName() {
        VersionBean version = Collections.max(versions);
        return String.format("%s:%s:%s", group, name, version.getVersionName());
    }

    @Override
    public String toString() {
        return "LibraryBean{" +
                "name='" + name + '\'' +
                ", group='" + group + '\'' +
                ", detail='" + detail + '\'' +
                ", docLink='" + docLink + '\'' +
                ", versions=" + versions +
                '}';
    }

    @Override
    public int compareTo(LibraryBean o) {
        return getFullyQualifiedName().compareTo(o.getFullyQualifiedName());
    }
}
